<template>
  <div>
    <div class="list">
      <strong>编辑:</strong>
      <div class="list">
        <div v-for="prod in productssRef" :key="prod.id">
          <CheckEdit
            v-model="prod.sell"
            v-model:text.trim="prod.title"
          ></CheckEdit>
        </div>
      </div>
    </div>

    <div class="list">
      <strong>销售中:</strong>
      <div>
        <template v-for="sell in getSell" :key="sell.id">
          <span>{{ sell.id }}</span>
          <strong>{{ sell.title }}</strong>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import CheckEdit from "./components/CheckEdit.vue";
import { ref, computed } from "vue";
const defaultSells = [
  { id: 1, sell: true, title: "iphone12" },
  { id: 2, sell: false, title: "xiaomi" },
  { id: 3, sell: true, title: "huawei" },
  { id: 4, sell: true, title: "vivo" },
];
export default {
  name: "App",
  components: { CheckEdit },
  setup() {
    const productssRef = ref(defaultSells);

    const getSell = computed(() => productssRef.value.filter((it) => it.sell));
    return {
      productssRef,
      getSell,
    };
  },
  data: () => ({
    checked: false,
    text: "ss",
  }),
};
</script>

<style>
.container {
  margin-top: 50px;
  width: 880px;
  margin: 50px auto;
}
.list {
  display: flex;
  margin: 1em 0;
  align-items: center;
}
strong {
  margin-right: 1em;
}
</style>
